package com.ouli.crowd.mvc.handler;

import com.ouli.crowd.entity.Admin;
import com.ouli.crowd.service.api.AdminService;
import com.ouli.crowd.service.api.RoleService;
import com.ouli.crowd.util.CrowdUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
public class TestHandler {
    @Autowired
    private AdminService adminService;

    @Autowired
    private RoleService roleService;

    private Logger logger = LoggerFactory.getLogger(TestHandler.class);


    @RequestMapping("/test/ssm.html")
    public String doTest(ModelMap modelMap, HttpServletRequest request){
        boolean judgeRequest = CrowdUtil.judgeRequestType(request);
        logger.info("judgeRequest="+judgeRequest);
        List<Admin> list = adminService.getAllAdmin();
        modelMap.addAttribute("adminList",list);
        //System.out.println(10/0);
//        String a = null;
//        System.out.println(a.length());
        return "target";
    }

    @RequestMapping("/send/array.html")
    public String testReceiveArrayOne(@RequestParam("array[]") List<Integer> array) {

        for (Integer number : array){
            System.out.println("number="+number);
        }
        return"target";
    }

    @Override
    public String toString() {
        return "TestHandler{" +
                "adminService=" + adminService +
                '}';
    }

    @ResponseBody
    @RequestMapping("/send/array/plan/three.html")
    public String receiveArrayPlanThree(@RequestBody Integer[] empIdArray){
        for (Integer empId:empIdArray) {
            System.out.println(empId);
        }

        return "success";
    }
}
